from models import db
from models.tags import Tag
class Task(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80),nullable=False)
    description = db.Column(db.String(200))
    publishtime = db.Column(db.DateTime,nullable=False)
    accomplishtime = db.Column(db.DateTime)
    timeneed = db.Column(db.Float)
    records = db.relationship('Record',
                    backref='task',lazy=True)

    def __init__(self, dic):
        for key,value in dic.items():
            setattr(self, key, value)

    def __repr__(self):
        return '{}:{}:{}:{}:{}'.format(self.name,self.publishtime
                                ,self.accomplishtime
                                ,self.timeneed
                                ,self.timeusage)
        
tags = db.Table(
        'tasktags',
        db.Column('record_id',db.Integer, db.ForeignKey('task.id')),
        db.Column('tag_id',db.Integer, db.ForeignKey('tag.id'))
)
